import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QLabel, QLineEdit, QDesktopWidget


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = QWidget()
    w.setWindowTitle('The first PyQt')

    w.move(0, 0)
    # 按钮
    btn = QPushButton('Button')
    btn.setParent(w)

    # 获取控件位置和大小
    x, y, width, height = w.frameGeometry().getRect()
    print(x, y, width, height)
    # 获取屏幕中心位置
    center_pointer = QDesktopWidget().availableGeometry().center()
    center_x = center_pointer.x()
    center_y = center_pointer.y()
    # 移动到屏幕中心
    w.move(int(center_x-width/2), int(center_y-height/2))

    # 文本
    label = QLabel('Text', w)
    label.setGeometry(50, 50, 50, 30)

    # 文本框
    line_edit = QLineEdit('User-name:', w).setGeometry(50, 100, 300, 20)
    w.resize(600, 300)
    w.show()
    app.exec_()  # 程序进行运行循环
